package com.sg.file.transform.provider.center;

import com.sg.file.common.conf.VisibleFileSizeConf;
import com.sg.file.transform.api.dto.TransformReqeust;
import it.sauronsoftware.jave.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * Created by asus on 2018/6/28.
 */
@Service
@Slf4j
public class VideoTranscode extends FFmpegTranscode {

    @Override
    public EncodingAttributes getEncodeAttr(TransformReqeust transformReqeust) {
        //设置音频参数
        AudioAttributes audio = new AudioAttributes();

        //设置视频参数
        VideoAttributes video = new VideoAttributes();
        //-vcodec
        video.setCodec("mpeg4");
        //如果为空则使用默认分辨率
        video.setSize(getVideoSize(transformReqeust));//-s width,height

        //设置转换器参数
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp4");//-f
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);

        return attrs;
    }

    /**
     * 根据视屏类型，获取视频转换的尺寸
     * @param transformReqeust
     * @return
     */
    private VideoSize getVideoSize(TransformReqeust transformReqeust){
        VisibleFileSizeConf.Size size = VisibleFileSizeConf.getVoideSize(transformReqeust.getTransformToFileSizeType());
        return new VideoSize(size.getWidth().intValue(),size.getHeight().intValue());
    }

}
